<template>
  <div class="waybill__item">
    <div class="top">
      <div class="order__num">
        <div class="line"></div>
        <div class="title">{{ detail.billOrderNo }}</div>
        <div class="copy copyNo" :data-clipboard-text="detail.billOrderNo.slice(5)" @click="handleCopy">复制</div>
      </div>
      <div class="status">{{ detail.billOrderStatusName }}</div>
    </div>
    <div class="other">
      <div class="time">
        <div class="title">{{ detail.billOrderTime }}</div>
      </div>
      <div class="sec__status" v-show="detail.billOrderSecStatusName">
        <div class="cir" :style="{ backgroundColor: `${detail.secStatusColor}` }"></div>
        <span>{{ detail.billOrderSecStatusName }}</span>
      </div>
    </div>
    <div class="step">
      <div class="content">
        <div class="cir"></div>
        <div class="value">{{ detail.sendProvinceName }}{{ detail.sendCityName }}{{ detail.sendCountyName }}</div>
      </div>
      <div class="line__box">
        <div class="line"></div>
        <div class="description">
          <div class="left">
            <span>{{ detail.goodsTypeDesc }}&nbsp;/&nbsp;</span>
            <span v-if="detail.goodsName">{{ detail.goodsName }}&nbsp;/&nbsp;</span>
          </div>
          <div class="right">
            {{ detail.remainAllot || 0 }}/{{ detail.totalAllot || 0
            }}{{ detail.settleType === SettleTypeEm.Trip.value ? '趟' : '吨' }}
          </div>
        </div>
      </div>
      <div class="content">
        <div class="cir"></div>
        <div class="value">
          {{ detail.receiveProvinceName }}{{ detail.receiveCityName }}{{ detail.receiveCountyName }}
        </div>
      </div>
    </div>
    <div class="goods__num" v-if="detail.billOrderStatus === BillAllStatusEm.WAIT_RE.value && detail.orderType === 1">
      <div class="goods__title">货源余量:</div>
      <div class="goods_speed">
        <div
          class="current__Speed"
          :style="{
            width: detail.remainAllot && detail.totalAllot ? `${(detail.remainAllot / detail.totalAllot) * 100}%` : 0
          }"
        ></div>
      </div>
      <div class="goods__memo">
        {{ detail.remainAllot || 0 }}/{{ detail.totalAllot || 0
        }}{{ detail.settleType === SettleTypeEm.Trip.value ? '趟' : '吨' }}
      </div>
    </div>
    <div class="btn__area">
      <div
        class="btn"
        :class="itemBtn.class"
        v-for="(itemBtn, index) in detail.operationBtns"
        :key="index"
        @click="itemBtn.fn"
      >
        {{ itemBtn.title }}
      </div>
    </div>
  </div>
</template>

<script>
import { defineComponent } from 'vue'
import { SettleTypeEm, BillAllStatusEm } from '../../utils/enums'
import { Toast } from 'vant'
import Clipboard from 'clipboard'
export default defineComponent({
  name: 'waybillItem',
  props: {
    detail: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  setup() {
    const handleCopy = () => {
      const clipboard = new Clipboard('.copyNo')
      clipboard.on('success', e => {
        Toast('复制成功')
        //  释放内存
        clipboard.destroy()
      })
      clipboard.on('error', e => {
        // 不支持复制
        Toast('当前手机不支持自动复制')
        // 释放内存
        clipboard.destroy()
      })
    }

    return {
      SettleTypeEm,
      BillAllStatusEm,
      handleCopy
    }
  }
})
</script>

<style lang="scss" scoped>
.waybill__item {
  width: 100%;
  background: #ffffff;
  border-radius: 8px;
  background: white;
  box-sizing: border-box;
  padding: 10px;
  margin-bottom: 10px;
  .top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 10px;
    margin-bottom: 10px;
    border-bottom: 1px solid #ededed;
    .line {
      width: 3px;
      height: 10px;
      background: #409eff;
      margin: 0 10px 0 -10px;
    }
    .order__num {
      font-size: 14px;
      font-weight: 400;
      color: #575c72;
      display: flex;
      align-items: center;
      .copy {
        margin-left: 10px;
        cursor: pointer;
      }
    }
  }
  .goods__num {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0 0 0;
    .goods__title {
      font-size: 14px;
      font-weight: 400;
      color: #575c72;
    }
    .goods_speed {
      height: 8px;
      width: 180px;
      border-radius: 4px;
      background: rgba(255, 182, 64, 0.2);
      position: relative;
      overflow: hidden;
      .current__Speed {
        width: 0;
        height: 100%;
        position: absolute;
        left: 0;
        top: 0;
        background: #ffb640;
      }
    }
    .goods__memo {
      font-size: 12px;
      font-weight: 400;
      color: #575c72;
    }
  }
  .other {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    .time {
      font-size: 14px;
      font-weight: 400;
      color: #575c72;
      display: flex;
      align-items: center;
    }
    .sec__status {
      .cir {
        width: 5px;
        height: 5px;
        background: #fc9e29;
        border-radius: 50%;
        margin-right: 5px;
      }
      .cir__red {
        background: #ff6459;
      }
      display: flex;
      align-items: center;
      height: 18px;
      background: rgba(159, 162, 175, 0.2);
      border-radius: 9px;
      line-height: 18px;
      padding: 0 5px;
      font-size: 11px;
      font-weight: 400;
      color: #767f8e;
    }
  }
  .step {
    .content {
      display: flex;
      align-items: center;
      .cir {
        width: 8px;
        height: 8px;
        border: 1px solid #75798d;
        box-sizing: border-box;
        margin-right: 6px;
        border-radius: 50%;
      }
      .value {
        font-size: 16px;
        font-weight: 600;
        color: #101736;
        line-height: 16px;
      }
    }
    .line__box {
      display: flex;
      align-items: center;
      position: relative;
      .line {
        position: absolute;
        width: 1px;
        left: 2.8px;
        top: -4px;
        height: 75px;
        background: #75798d;
      }
      .description {
        width: 318px;
        height: 36px;
        background: #f7f9fc;
        border-radius: 6px;
        font-size: 14px;
        font-weight: 400;
        color: #575c72;
        line-height: 20px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        box-sizing: border-box;
        padding: 8px 10px;
        margin: 15px 0 15px 10px;
      }
    }
  }
  .btn__area {
    display: flex;
    align-items: center;
    margin-top: 10px;
    justify-content: flex-end;
    .btn {
      width: 80px;
      height: 34px;
      font-size: 14px;
      line-height: 34px;
      font-weight: 400;
      border-radius: 4px;
      line-height: 34px;
      text-align: center;
      box-sizing: border-box;
      margin-right: 10px;
    }
    .default__btn {
      border: 1px solid #575c72;
      color: #575c72;
    }
    .active__btn {
      background: linear-gradient(125deg, #74cdff 0%, #409eff 100%);
      border-radius: 4px;
      color: white;
    }
  }
}
</style>
